using System;
using System.Collections;
using System.Collections.Generic;
using BMCommon;
using Data;
using Holoville.HOTween;
using TMPro;
using UnityEngine;

public class PackageClearPopupHandler : MonoBehaviour, IPopupWnd, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterPopup(object param)
	{
		PackageClearPopupHandler.closeMessage = "Ok";
		this.coloredPapaer.SetActive(false);
		this.icon.SetActive(true);
		this.title.gameObject.transform.localScale = Vector3.zero;
		this.title.gameObject.transform.localPosition = Vector3.zero;
		this.icon.gameObject.transform.localScale = Vector3.zero;
		this.message.text = string.Format("\"{0}\"\nPackage Completed!", DataContainer<Data.Root>.Data.currentPackage.display);
		this.btnRoot.gameObject.transform.localScale = Vector3.zero;
		bool flag = false;
		int num = Array.FindIndex<Package>(DataContainer<Data.Root>.Data.packages, (Package item) => item == DataContainer<Data.Root>.Data.currentPackage);
		for (int i = num; i < DataContainer<Data.Root>.Data.packages.Length; i++)
		{
			if (i != num && !DataContainer<Data.Root>.Data.packages[i].isPremium && DataContainer<Data.Root>.Data.packages[i].mode.Equals(GameMode.packageMode))
			{
				flag = true;
				this.nextPackageIndex = i;
				break;
			}
		}
		if (flag)
		{
			this.sureRoot.SetActive(false);
			this.nextRoot.SetActive(true);
		}
		else
		{
			this.sureRoot.SetActive(true);
			this.nextRoot.SetActive(false);
		}
		base.StartCoroutine(this.coClearPopupAnimation());
	}

	public void OnLeavePopup()
	{
	}

	private void OnClick_ok()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ClosePopup("PackageClearPopup", true);
	}

	private void OnClick_nextPackage()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		DataContainer<Data.Root>.Data.currentPackage = DataContainer<Data.Root>.Data.packages[this.nextPackageIndex];
		DataContainer<Data.Root>.Data.currentLevel = DataContainer<Data.Root>.Data.currentPackage.levels[0];
		Scene.ClosePopup("PackageClearPopup", false);
	}

	private void OnClickReplay()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		PackageClearPopupHandler.closeMessage = "Replay";
		Scene.ClosePopup("PackageClearPopup", true);
	}

	private IEnumerator coClearPopupAnimation()
	{
		BMSoundHelper.Play("se_packageclear", false, 1f);
		Sequence seq = new Sequence(new SequenceParms().OnComplete(delegate()
		{
		}));
		seq.Insert(0f, this.title.gameObject.Popup(0.5f));
		seq.Insert(0.5f, HOTween.To(this.title.gameObject.transform, 0.3f, new TweenParms().Prop("localPosition", new Vector3(0f, 6.58f, 0f))));
		seq.Insert(0.7f, this.icon.gameObject.Popup(0.5f));
		seq.Play();
		yield return new WaitForSeconds(1.2f);
		this.coloredPapaer.SetActive(true);
		yield return new WaitForSeconds(0.3f);
		HOTween.To(this.btnRoot.gameObject.transform, 0.5f, new TweenParms().Prop("localScale", new Vector3(1f, 1f, 1f)).Ease(EaseType.EaseOutBack));
		yield return new WaitForSeconds(0.3f);
		yield break;
	}

	private void OnEscape()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ClosePopup("PackageClearPopup", true);
	}

	[SerializeField]
	private tk2dCamera cam;

	[SerializeField]
	private GameObject curtain;

	public static string closeMessage;

	public GameObject icon;

	public GameObject btnRoot;

	public TextMeshPro message;

	public TextMeshPro title;

	public GameObject sureRoot;

	public GameObject nextRoot;

	public GameObject coloredPapaer;

	private List<Package> packageList;

	private int nextPackageIndex;
}
